﻿using System.Collections.Generic;
using System.Linq;
using Citi.Scheduler.Domain.Utils;

namespace Citi.Scheduler.Domain
{
    public partial class Escalation
    {
        public List<Escalation> NextEscalations(int routineId)
        {
            return SelectByRoutine(routineId).Where(x => !x.RoutineErrorEmails.Any()).ToList();
        }

        public List<Escalation> SelectByRoutine(int routineId)
        {
            return Context.Instance.Escalations.Where(x => x.RoutineId == routineId).ToList();
        }

        //public string AllUsers
        //{
        //    get
        //    {
        //        var users = string.Empty;

        //        if (Coordinator && User.Manager != null)
        //            users += string.Concat(User.Manager.Soeid, "; ");

        //        if (Manager && User.Manager != null && User.Manager.Manager != null)
        //            users += string.Concat(User.Manager.Manager.Soeid, "; ");

        //        if (Head && User.Manager != null && User.Manager.Manager != null && User.Manager.Manager.Manager != null)
        //            users += string.Concat(User.Manager.Manager.Manager.Soeid, "; ");

        //        if (!string.IsNullOrEmpty(OtherEmail1))
        //            users += string.Concat(OtherEmail1, "; ");

        //        if (!string.IsNullOrEmpty(OtherEmail2))
        //            users += string.Concat(OtherEmail2, "; ");

        //        return users;
        //    }
        //}

        public string AllUsers
        {
            get
            {
                var users = string.Concat(User.Soeid, "; ");

                if (Coordinator && User.Manager != null)
                    users += string.Concat(User.Manager.Soeid, "; ");

                if (Manager && User.Manager != null && User.Manager.Manager != null)
                    users += string.Concat(User.Manager.Manager.Soeid, "; ");

                if (Head && User.Manager != null && User.Manager.Manager != null && User.Manager.Manager.Manager != null)
                    users += string.Concat(User.Manager.Manager.Manager.Soeid, "; ");

                if (!string.IsNullOrEmpty(OtherEmail1))
                    users += string.Concat(OtherEmail1, "; ");

                if (!string.IsNullOrEmpty(OtherEmail2))
                    users += string.Concat(OtherEmail2, "; ");

                return users;
            }
        }
    }
}
